Introduction
This crate is for creating Email
objects.
- It allows you to have Email as a type. i.e.
let emails : Vec<Email> = vec![]
. - The
Email
type guarantees to be validated. Once it is created, you can be confident it's safe to use as an email. - The
Email
type can also be used as strings. This allows interoptability with lots of connector functions which will take a String. - It supports Serde out of the box. For Serialisation with CLIs, requests, etc.
(Note this library will not check if the Email address exists. It only validates that it looks correct.)
Features
serde
Default - Enables serde serialisation and deserialisation.sea-orm
- Enables Sea Orm use with DB entities.
Usage
Building your own email addresses
use Email;
let email = from_str.expect;
Validating the email address yourself
use is_valid_email;
if is_valid_email
Serialisation / Deserialisation
use Email;
use serde_json;
// Some JSON input data as a &str. Maybe this comes from the user.
let data = r#"
{
"name": "John Doe",
"email": "john@example.com"
}"#;
// Parse the string of data into serde_json::Value.
let person: Person = from_str.unwrap;
// Access parts of the data by indexing with square brackets.
println!;
Sea Orm Entities
You can use the Email
type with Sea Orm, including using it to save data to the DB.
Underneath it will serialise to a Text
type within the DB.
use *;
use Deserialize;
use Serialize;
use Email;
Special Thanks
The validation is all done by the email_address crate.